﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no" />
    <title>新快递</title>
    <link href="/View_Mobile/Frozenui1.3/css/frozen.css" rel="stylesheet" />
    <script src="/View_Mobile/JS/zepto.min.js"></script>
    <script src="/View_Mobile/Frozenui1.3/js/frozen.js"></script>
    <script src="/View_Mobile/JS/avalon.mobile.min.js"></script>
    <script src="/View_Mobile/JS/ComFunJS.js?jsver=20160425"></script>
    <script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
    <script>
        //document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {
        //    //隐藏右上角按钮
        //    WeixinJSBridge.call('hideOptionMenu');
        //});

        var height = 0;
        var width = 0;
        var strId = "";


        var model = avalon.define({
            $id: "model",
            code: "KDGL",
            wximg: "",
            jsr:"",
            ctData: { "Title": "", "ImgUrl": "", "JSUser": "", "Remark": "" },
            savedata: function () {
                $("#imglist .tpli").each(function () {
                    if ($(this).hasClass("wximg")) { //微信上传未处理的图片
                        if (model.wximg) {
                            model.wximg += ",";
                        }
                        model.wximg += $(this).attr("itemid");

                    } else {
                        if (model.ctData.ImgUrl) {
                            model.ctData.ImgUrl = model.ctData.ImgUrl + ',' + $(this).attr("itemid");
                        }
                        else {
                            model.ctData.ImgUrl = $(this).attr("itemid");
                        }
                    }

                })
                if (!model.jsr) {
                    $.tips({
                        content: "请选择接收人",
                        stayTime: 2000,
                        type: "warn"
                    })
                    return;
                }

                if (!model.wximg &&!model.ctData.ImgUrl) {
                    $.tips({
                        content: "请上传图片",
                        stayTime: 2000,
                        type: "warn"
                    })
                    return;
                }
                

                var lg = $.loading({
                    content: '保存中...',
                })
                
                $.post("/API/VIEWAPI.ashx?Action=KDGL_ADDKDGL&jsr=" + model.jsr + "&r=" + Math.random(), { "P1": JSON.stringify(model.ctData.$model), "P2": model.wximg }, function (data) {
                    lg.hide();
                    var data = $.parseJSON(data);
                    if (data.ErrorMsg == "") {
                        $("button").hide();
                        var el = $.tips({
                            content: "保存成功！",
                            stayTime: 2000,
                            type: "success"
                        })
                        el.on("tips:hide", function () {
                            //window.location.reload();
                            window.location.replace(location.href);
                        })
                    }
                    else {
                        $.tips({
                            content: "保存失败，原因：" + data.ErrorMsg,
                            stayTime: 2000,
                            type: "warn"
                        })
                        //alert(data.ErrorMsg);
                    }
                })

            },
            repshow: function () {
                $(this).parent().siblings().removeClass("active");
                $(this).parent().addClass("active");
            },
            selperson: function () {
                $("#iframep").attr("src", "/View_Mobile/UI/UI_PERSON.html?r=" + Math.random() + "&Users=" + model.jsr);
                $("#content").hide();
                $("#iframep").show();

                var cheight = height;
                var cwidth = width;

                $("#iframep").css("height", cheight);
                $("#iframep").css("width", cwidth);

            }

        });

        function goback() {
            $("#content").show();
            $("#iframep").hide();
        }
        function goconfirm(json) {
            if (json != null) {
                $("#kh_fzry").removeClass("ui-txt-muted");
                $("#kh_fzry").html(json.vuser);
                //model.ctData.JSUser = json.vusername;
                model.jsr = json.vusername;
            }
            else {
                $("#kh_fzry").addClass("ui-txt-muted");
                $("#kh_fzry").html('请选择接收人');
                //model.ctData.JSUser = '';
                model.jsr = "";
            }

            $("#content").show();
            $("#iframep").hide();
        }

        avalon.ready(function () {
            width = document.documentElement.clientWidth;
            height = document.documentElement.clientHeight;

            $("#iframep").attr("src", "/View_Mobile/UI/UI_PERSON.html?r=" + Math.random() );

            ComFunJS.uploadimg();
            //ComFunJS.chooseUser();
        })
        function back() {
            window.history.back();
        }
    </script>
    <style type="text/css">

        .ms-controller, [ms-controller] {
            display: none;
        }

        .ui-form-item .wspan {
            width: 100%;
            display: -webkit-box;
            -webkit-box-sizing: border-box;
            box-sizing: border-box;
            -webkit-appearance: none;
            border: 0;
            background: 0 0;
            padding-left: 95px;
        }

            .ui-form-item .wspan img {
                width: 50px;
                height: 50px;
                padding-right: 3px;
            }

        .sctp {
            color: #18b4ed;
            right: 4px;
            top: -5px;
            z-index: 9;
            width: 20px;
            height: 20px;
            background: #fff;
            border-radius: 13px;
            line-height: 20px;
            text-indent: -3px;
            position: absolute;
            font-size: 25px;
        }

        .imgxl {
            position: relative;
            float: left;
            padding-top: 0;
            height: 50px;
            width: 50px;
            padding-right: 10px;
            margin-left: 0px;
            margin-bottom: 5px;
        }

        .tpxs {
            height: 50px;
            width: 50px;
            position: absolute;
            top: 0;
            left: 0;
            z-index: 1;
            background-repeat: no-repeat;
            -webkit-background-size: cover;
        }
    </style>
</head>
<body ms-controller="model">
    <div id="content">
        <!--<div class="ui-footer ui-footer-stable ui-btn-group ui-border-t">
            <button class="ui-btn-lg ui-btn-primary" ms-click="savedata()">
                新增请假出差
            </button>
        </div>-->
        <div class="ui-footer ui-footer-stable ui-btn-group ui-border-t">
            <button class="ui-btn-lg" onclick="back()">
                取消
            </button>
            <button class="ui-btn-lg ui-btn-primary" id="save" ms-click="savedata()">
                录入快递
            </button>
        </div>
        <section class="ui-container">
            <div class="ui-form ui-border-t">
                <div class="ui-form-item ui-border-b" style="height:auto">
                    <label>
                        接收人
                    </label>
                    <div class="ui-txt-muted ui-whitespace ui-form-item-link" style="padding-left: 95px;text-align:justify" id="kh_fzry" ms-click="selperson()">请选择接收人</div>
                    <!--<input class="openEnterpriseContact_invoke" placeholder="请选择接收人1" />
                    <input class="openEnterpriseContact_invoke" placeholder="请选择接收人2" />-->
                </div>

                <div class="ui-form-item ui-border-b" style="height:auto;min-height:44px">
                    <label>
                        上传图片
                    </label>

                    <div class="wspan" style="padding-top: 5px; height: auto;display:block">
                        <ul id="imglist">
                            <li class="imgxl scli"><img id="add_pit" src="/View_Mobile/Images/icon-add.png" /></li>
                        </ul>
                        <div style="clear:both"></div>
                    </div>
                </div>
                <div class="ui-form-item ui-border-b ui-form-item-textarea" style="height:auto;min-height:44px">
                    <label>
                        备注
                    </label>
                    <textarea placeholder="请输入备注" style="height:80px;" class="chackTextarea-area" ms-duplex="ctData.Remark"></textarea>
                </div>
            </div>
        </section>
    </div>

    <iframe id="iframep" src="" style="display: none; margin-bottom: -7px;" frameborder="0"></iframe>
</body>
</html>
